#pragma once
#include"Hash.h"

template<class K,class V,class Hash=HashFunc<K>>
class Unordered_Map
{
public:
	struct KeyOfMap
	{
		const K& operator()(const pair<K,V>& kv)
		{
			return kv.first;
		}
	};
	typedef typename HashTables<K, pair<const K,V>, KeyOfMap, Hash>::Iterator iterator;
	typedef typename HashTables<K, pair<const K,V>, KeyOfMap, Hash>::ConstIterator const_iterator;

	iterator begin()
	{
		return _ht.Begin();
	}
	iterator end()
	{
		return _ht.End();
	}

	const_iterator begin() const
	{
		return _ht.Begin();
	}
	const_iterator end()const
	{
		return _ht.End();
	}

	V& operator[](const K& key)
	{
		pair<iterator, bool> ret = insert(make_pair(key,V()));
		return ret.first->second;
	}

	pair<iterator,bool>insert(const pair<K,V>& kv)
	{
		return _ht.Insert(kv);
	}

	iterator  find(const K& key)
	{
		return _ht.Find(key);
	}
	bool erase(const K& key)
	{
		return _ht.Erase(key);
	}
private:
	HashTables<K,pair<const K,V>, KeyOfMap, Hash> _ht;
};
